package uk.co.tarbard.svnreporter;

import java.io.IOException;
import java.util.TimerTask;

import uk.co.tarbard.svnreporter.logentries.ILogRetriever;

/**
 * This class is the entry point for this application 
 * it is fired using a spring managed scheduled timer task
 */
public class Jobbie extends TimerTask {

	private final ILogRetriever logRetriever;
	private final IXMLMarshaller xmlMarshaller;
	private final IWriter writer;

	public Jobbie(ILogRetriever logRetriever, IXMLMarshaller xmlMarshaller, IWriter writer) {
		this.logRetriever = logRetriever;
		this.xmlMarshaller = xmlMarshaller;
		this.writer = writer;
	}

	/**
	 * This is called by the timer task and uses the ILogRetriever to get the log entries
	 * and the IXMLMarshaller to create XML for them which is used by the timeline
	 */
	@Override
	public void run() {
		String content = xmlMarshaller.createXML(logRetriever.getLogEntries());
		try {
			writer.write("output.xml", content);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
